package com.example.presentshopping.ui.activity

import BaseRecyclerAdapter
import BaseRecyclerHolder
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import com.example.presentshopping.R
import com.example.presentshopping.config.base.BaseMvpActivity
import com.example.presentshopping.config.bean.CumulativeBean
import com.example.presentshopping.config.bean.StartersBean
import com.example.presentshopping.mvp.presenter.PublicPresenter
import com.example.presentshopping.net.http.HttpRequest
import com.example.presentshopping.net.http.HttpURL
import com.example.presentshopping.utils.tool.GsonUtils
import com.yanzhenjie.recyclerview.SwipeRecyclerView
import kotlinx.android.synthetic.main.activity_cumulative.*

//累计提现
class CumulativeActivity : BaseMvpActivity() {

    var cunlis: CumulativeBean? = null

    private var queryInfoPresenter: PublicPresenter? = null
    var baseRecyclerAdapter: BaseRecyclerAdapter<CumulativeBean.DataBean.ListBean>? = null

    var page = 1
    override val layoutId: Int
        get() = R.layout.activity_cumulative

    override fun initView(savedInstanceState: Bundle?) {
        title_main_tv.leftBackImageTv.setOnClickListener { finish() }
        queryInfoPresenter = PublicPresenter(context, false, "")
        queryInfoPresenter?.attachView(this)
        setAdater()
        RgetGoodsList()
        swip_layouy?.setLoadMoreListener {
            page++
            RgetGoodsList()
        }

    }

    fun RgetGoodsList() {
        queryInfoPresenter?.netWorkRequestGet(HttpURL.Req_getWithdrawalList,
            HttpRequest.getTeamGoodsList(1, page, 10))
    }

    fun setAdater() {
        baseRecyclerAdapter = object : BaseRecyclerAdapter<CumulativeBean.DataBean.ListBean>(this,
            null,
            R.layout.item_cumulative) {
            @SuppressLint("SetTextI18n")
            override fun convert(
                holder: BaseRecyclerHolder?,
                data: CumulativeBean.DataBean.ListBean,
                position: Int,
                isScrolling: Boolean,
                selectedPosition: Int
            ) {
                val create_time = holder?.getView<TextView>(R.id.create_time)
                val total = holder?.getView<TextView>(R.id.total)

                create_time?.text = "提现时间：" + data?.create_time
                total?.text = "提现金额：" + data?.total

            }

        }
        swip_layouy.useDefaultLoadMore()
        swip_layouy.loadMoreFinish(false, true)
        swip_layouy.adapter = baseRecyclerAdapter
    }

    override fun onDestroy() {
        queryInfoPresenter?.detachView()
        super.onDestroy()

    }

    override fun showToast(msg: String?) {

    }

    override fun onSuccess(data: String?) {
        cunlis = GsonUtils.getGson().fromJson(data, CumulativeBean().javaClass)

        if (cunlis?.data?.list?.size!! > 0) {
            swip_layouy.loadMoreFinish(false, true)
            baseRecyclerAdapter?.setData(cunlis?.data?.list)
        } else {
            swip_layouy.loadMoreFinish(true, false)
        }


    }

    override fun onFailure(e: Throwable?, code: Int, msg: String?, isNetWorkError: Boolean) {

    }
}